<template>
  <div>
    <!--博客头部-->
    <Header></Header>

    <!--博客内容-->
    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
          <el-card>
            <h4>
              <router-link :to="{name: 'BlogDetail', params:{blogId:blog.id}}">
                {{ blog.title }}
              </router-link>
            </h4>
            <p>{{ blog.description }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>

      <el-pagination
          class="my-page"
          background
          layout="prev, pager, next"
          :current-page="currentPage"
          :page-size="pageSize"
          @current-change=page
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import Header from "@/components/Header";


export default {
  name: "Blogs",
  components: {Header},
  data() {
    return {
      blogs: {},
      currentPage: 1,
      pageSize: 5,
      total: 0
    }
  },
  methods: {
    page(currentPage) {
      const _this = this;

      _this.$axios.get('/blogs/blog?currentPage=' + currentPage).then(res => {
        console.log(res.data)
        this.blogs = res.data.data.records
        this.total = res.data.data.total
        this.currentPage = res.data.data.current
        this.pageSize = res.data.data.size
      })

    }
  },
  created() {
    this.page(1)
  }
}
</script>

<style scoped>
.my-page {
  margin: 0px auto;
  text-align: center;
}
</style>